﻿@page
@using JetBrains.Space.AspNetCore.Authentication
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="row">
    <div class="col-4">
        <div class="row mb-2">
            <div class="col-12">
                <img src="/space-attachments/@User.Identity!.GetClaimValue(SpaceClaimTypes.ProfilePicture)" alt="Profile picture" width="200" height="200" />
            </div>
        </div>
        
        <div class="row mb-2">
            <div class="col-12">
                <h4>Contact details</h4>
                <ul>
                    @foreach (var profileMessenger in Model.MemberProfile.Messengers)
                    {
                        <li>@profileMessenger</li>
                    }
                    @foreach (var profilePhone in Model.MemberProfile.Phones)
                    {
                        <li>@profilePhone</li>
                    }
                    @foreach (var profileEmail in Model.MemberProfile.Emails)
                    {
                        <li><a href="mailto:@Html.Raw(profileEmail.Email)">@profileEmail.Email</a></li>
                    }
                    @foreach (var profileLink in Model.MemberProfile.Links)
                    {
                        <li><a href="@Html.Raw(profileLink)">@profileLink</a></li>
                    }
                </ul>
            </div>
        </div>
        
        <div class="row mb-2">
            <div class="col-12">
                <h4>Personal data</h4>
                @if (Model.MemberProfile.Birthday != null)
                {
                    <small>Birthday</small><br/>
                    @Model.MemberProfile.Birthday?.ToString("yyyy-MM-dd")<br/>
                }
                
                <small>Languages</small><br/>
                @string.Join(", ", Model.MemberProfile.Languages.Select(l => l.Language.Name)), English
            </div>
        </div>
    </div>
    
    <div class="col-6">
        <div class="row mb-2">
            <div class="col-12">
                <h2>@Model.MemberProfile.Name.FirstName @Model.MemberProfile.Name.LastName</h2>
                @Model.MemberProfile.Locations[0].Location.Name
            </div>
        </div>
        
        <div class="row mb-2">
            <div class="col-12">
                <h4>Activity</h4>
                <canvas id="activityChart" width="600" height="400"></canvas>
                
                <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
                <script>
                    document.addEventListener('DOMContentLoaded', function() {    
                        new Chart(
                            document.getElementById("activityChart"),
                            {
                                "type": "radar",
                                "data": { 
                                    "labels": ["Issues created", "Issues resolved", "Reviews created", "Reviews participated", "TODO items completed", "Meetings"],
                                    "datasets": [{
                                        "label": "Activity",
                                        "data": [ 
                                            @Model.IssuesCreatedThisWeek, @Model.IssuesResolvedThisWeek,
                                            @Model.ReviewsCreatedThisWeek, @Model.ReviewsParticipatedThisWeek, 
                                            @Model.TodoClosedThisWeek, @Model.MeetingsThisWeek
                                        ],
                                        "backgroundColor":"rgba(22,155,207,0.2)"
                                    }]
                                },
                                "options": {
                                    "elements": {
                                        "line": {
                                            "tension": 0,
                                            "borderWidth": 3
                                        }
                                    }
                                }
                            });
                    }, false);
                </script>
            </div>
        </div>
        
        @if (Model.MeetingsToday.Count > 0)
        {
            <div class="row mb-2">
                <div class="col-12">
                    <h4>Meetings today</h4>
                    <ul class="list-group">
                        @foreach (var meeting in Model.MeetingsToday.OrderBy(it => it.OccurrenceRule.Start))
                        {
                            <li class="list-group-item">
                                <small>@meeting.OccurrenceRule.Start.ToString("hh:mm tt") - @meeting.OccurrenceRule.End.ToString("hh:mm tt") (@meeting.OccurrenceRule.Timezone.Id)</small><br/>
                                @meeting.Summary
                                
                                @if (meeting.ConferenceData?.Url != null)
                                {
                                    <a href="@Html.Raw(meeting.ConferenceData.Url.TrimEnd('/'))/" class="btn-sm btn-secondary">join</a>
                                }
                            </li>
                        }
                    </ul>
                </div>
            </div>
        }
        
        <div class="row mb-2">
            <div class="col-12">
                <h4>Absences</h4>
                <ul class="list-group">
                    @foreach (var absence in Model.Absences.Take(5))
                    {
                        <li class="list-group-item">
                            <small>@absence.Since.ToString("yyyy-MM-dd") - @absence.Till.ToString("yyyy-MM-dd")</small><br/>
                            @absence.Description
                        </li>
                    }
                </ul>
            </div>
        </div>
        
        <div class="row mb-2">
            <div class="col-12">
                <h4>Teams</h4>
                <ul class="list-group">
                    @foreach (var membership in Model.MemberProfile.Memberships)
                    {
                        <li class="list-group-item">
                            @if (membership.Since != null)
                            {
                                <small>
                                    @membership.Since?.ToString("yyyy-MM-dd")
                                    
                                    @if (membership.Till != null)
                                    {
                                        <text>- @membership.Till?.ToString("yyyy-MM-dd")</text>
                                    }
                                 </small><br/>
                            }
                            
                            <em>@membership.Role.Name</em> in <em>@membership.Team.Name</em>
                        </li>
                    }
                </ul>
            </div>
        </div>
    </div>
</div>